package com.cn.crmsystem.service.censusService.impl;

import com.cn.crmsystem.mapper.censusMapper.MailListMapper;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.service.censusService.MailListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
//from ldk
@Service
public class MailListServiceImpl implements MailListService {
    @Autowired()
    private MailListMapper mailListMapper;

    @Override
    public ResultJson selectUser() {

    ResultJson resultJson=new ResultJson();

       List<Map<String,Object>> userList=mailListMapper.selectUser();

        Long count=mailListMapper.selectCount();



        if (userList!=null && userList.size()>0){
            return resultJson.getSuccess("成功",userList,count);
        }else{
            return resultJson.getFail("失败");
       }


    }

    @Override
    public ResultJson selectForIf(String selectkuang) {
        ResultJson resultJson=new ResultJson();
        Map<String,Object> map=new HashMap<>();
        if(selectkuang!=null  ){
            boolean  selectkuangpd=selectkuang.matches("[0-9]+");
            System.out.println(selectkuang+"1111111111111111111111111111111111111111111111");
            if(selectkuangpd==true){
                map.put("phone",selectkuang);
            }else if(selectkuangpd!=true){
                map.put("userName",selectkuang);
            }
        }
        List<Map<String,Object>> userList=mailListMapper.selectForIf(map);
        if (userList!=null && userList.size()>0){
            return resultJson.getSuccess("成功",userList);
        }else{
            return resultJson.getFail("失败");
        }
    }

    @Override
    public ResultJson selectDepartment() {
        ResultJson resultJson=new ResultJson();
        List<Map<String,Object>> userList=mailListMapper.selectDepartment();
        if (userList!=null && userList.size()>0){
            return resultJson.getSuccess("成功",userList);
        }else{
            return resultJson.getFail("失败");
        }
    }


}
